/**
 * jQuery truemouseout - fires the given function when the mouse
 * leaves the area contained by the selected element, i.e. doesn't
 * fire when over an inner element.  Note, if you want to force the
 * event to fire, you should use $('elm').mouseout();
 *
 * @author Remy Sharp (leftlogic.com)
 * @date 2007-05-17
 * @example $("img").truemouseout(function(e) { console.log(e); });
 *
 * @name truemouseout
 * @type event
 * @param Function function to fire when event is triggered
 * @cat Plugin
 */
 
(function($) {
  function contains(p, c) { 
    if (c == p) {
      return true;
    } else if (c.parentNode == document) {
      return false;
    } else if (c.parentNode == p) {
      return true;
    } else {
      return contains(p, c.parentNode);
    }
  }

  $.fn.truemouseout = function(fn) {
    return this.mouseout(function(e) {
      var t = $.browser.msie ? e.toElement : e.relatedTarget;
      if (t && contains(this, t)) {
        return false;
      } else {
        fn.call(this, e);
        return true;
      }
    });
  };  
})(jQuery);